package org.nyt.medicalstore.repository;

import org.nyt.medicalstore.model.SymptomDrugRelation;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Optional;

public interface SymptomDrugRelationRepository extends JpaRepository<SymptomDrugRelation,Long> {
    //根据药品和症状查找
    @Query("SELECT r FROM SymptomDrugRelation r WHERE r.symptom.id = :symptomId AND r.drug.id = :drugId")
    Optional<SymptomDrugRelation> findBySymptomAndDrug(
            @Param("symptomId") Long symptomId,
            @Param("drugId") Long drugId);
    //根据药品和症状删除
    @Modifying
    @Query("DELETE FROM SymptomDrugRelation r WHERE r.symptom.id = :symptomId AND r.drug.id = :drugId")
    void deleteBySymptomAndDrug(
            @Param("symptomId") Long symptomId,
            @Param("drugId") Long drugId);
}
